Repository navigation
Conversation
| // execute the code to ensure all tests pass. | ||
|
|
||
| export function getAngleType(angle) { | ||
| // TODO: Implement this function |
There was a problem hiding this comment.
What do you think happens when a function is declared twice, once at the top and again right inside itself without the inner one ever being called?
There was a problem hiding this comment.
I had to have a read about it and it seems that the function would be redefined inside of itself resulting in the inner function being called instead, but only if it needed to be a recursive one. In this situation, it would look confusing, but would still do the intended job.
However, I think there might have been a misunderstanding with the diff. I only changed the function declaration/export style slightly, so the original declaration in red was replaced by the implementation in green; the function isn't declared twice. I wondered about this because a similar comment was added to another task (implement-isProperFraction) on a function that was also in the deleted code. Could you clarify if I'm missing something?
There was a problem hiding this comment.
You are spot on! That was entirely on my end due to viewing the diff in Unified View, which made the replaced code look like a duplicate declaration. Your implementation looks completely correct, no double declaration at all. Thanks for clearing that up, and great eye on catching that diff quirk!
| // execute the code to ensure all tests pass. | ||
|
|
||
| export function getAngleType(angle) { | ||
| // TODO: Implement this function |
There was a problem hiding this comment.
What happens if someone passes a non-number like "90" or null here? Should we add validation
There was a problem hiding this comment.
Good point. I did not take that into consideration. Passing a regular string would return an "invalid angle", but an empty one or null would not
|
|
||
| // TODO: Write tests to cover all cases, including boundary and invalid cases. | ||
| // Example: Identify Right Angles | ||
|
|
There was a problem hiding this comment.
Should we add tests for zero and negative numbers too, just to check how those boundary cases are handled
There was a problem hiding this comment.
Awesome update! Checking for zero and negative numbers makes the test suite much stronger. Everything looks solid here.
| // execute the code to ensure all tests pass. | ||
|
|
||
| export function isProperFraction(numerator, denominator) { | ||
| // TODO: Implement this function |
There was a problem hiding this comment.
Looks like this function is declared twice here. What do you think happens to that inner function since it's never called
There was a problem hiding this comment.
I changed the function declaration/export style slightly and if you view the file it's more clear that the function has been declared once
|
|
||
| // TODO: Write tests to cover all cases. | ||
| // What combinations of numerators and denominators should you test? | ||
|
|
There was a problem hiding this comment.
What happens if the denominator is 0? Should we add a test case to see how the function handles that?
There was a problem hiding this comment.
Awesome, I see you’ve already implemented this fix! Everything looks good here.
| return "invalid"; | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Is there any debug logging at the bottom of the file that we should remove before finalizing?
| // execute the code to ensure all tests pass. | ||
|
|
||
| export function getCardValue(card) { | ||
| // TODO: Implement this function |
There was a problem hiding this comment.
Just like the other files, this function is declared twice. What happens to the inner function since it isn't exported or called
There was a problem hiding this comment.
once again, the function is declared once.. The export statement simply makes that existing function available to other modules; it does not declare another function or create an inner function. Your comments are written on the deleted sections
There was a problem hiding this comment.
Thanks for pointing this out! Just like in the other exercise, this was down to how I was viewing the diff in GitHub (Unified View showing the old red lines alongside the new green lines). Your code actually only declares the function once and is completely fine. Great job on the implementation!
| cardRank == "10" | ||
| ) { | ||
| return Number(cardRank); | ||
| } else { |
There was a problem hiding this comment.
The instructions above mention that an invalid card string should throw an error. How does returning the string "invalid" compare to throwing an error
There was a problem hiding this comment.
returning the string "invalid" would still allow the program to continue running without interruption, whereas throwing an error indicates a more serious issue that requires immediate attention and handling
Edit: I see now that some misunderstandings happened due to us looking at different versions of the file
There was a problem hiding this comment.
Spot on! You've captured the exact difference in control flow—returning a value allows execution to continue silently, whereas throwing an error halts execution and forces the caller to handle the edge case explicitly.
Also, completely agree regarding the diff mix-up thanks for bearing with me while I sorted out my view settings!
| ) { | ||
| return Number(cardRank); | ||
| } else { | ||
| return "invalid"; |
There was a problem hiding this comment.
What happens to the throw new Error statement right after return "invalid"; on line 57? Will that error ever actually be reached by the program?
There was a problem hiding this comment.
line 56-59: assert.throws(
() => getCardValue(""),
Error,
"Should throw an error for empty input"
| throw new Error(`Expected a number followed by a suit, but got "${card}"`); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Is there any debug logging (console.log) at the bottom of the file that we should remove before finalizing or committing our code?
There was a problem hiding this comment.
function getCardValue(card) {
// implementation
}
export { getCardValue };
| // To learn how to test whether a function throws an error as expected in Jest, | ||
| // please refer to the Jest documentation: | ||
| // https://jestjs.io/docs/expect#tothrowerror | ||
| // -----number cards------ |
There was a problem hiding this comment.
GREAT WORK HERE!
but notice how all the number card tests (2 through 9) follow the exact same pattern. Is there a built-in Jest feature (like test.each) we could use here to keep our tests DRY (Do not repeat yourself) and avoid repeating code
There was a problem hiding this comment.
thanks! it's great to know how to avoid repeating the code
dkrest1
left a comment
There was a problem hiding this comment.
Great job working through these! Your logic and test coverage for edge cases and errors are really strong.
Before finalizing, just double-check for:
-
Duplicate function declarations in your implementation files.
-
Leftover debug logs (console.log) that can be removed.
DRY tests (like using test.each for repetitive test cases).
Thanks for sharing your progress, keep up the great work!
dkrest1
left a comment
There was a problem hiding this comment.
Great work on this PR, Diana! 🚀
Thank you for working through all the feedback so thoroughly and for bearing with me through the initial diff viewer confusion. You’ve done a great job restructuring the tests, applying edge-case coverage for negative numbers and zero, and understanding the core mechanics between returning error strings vs. throwing errors.
Everything looks clean, accurate, and well-tested now. Approved!
Learners, PR Template
Self checklist
Task code
CYF-1059
Changelist
Wrote function implementations and tests in Node and Jest covering a variety of cases.